﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Security.Permissions;

namespace hpm
{
    class clsNgheNghiep
    {
        DAL da = new DAL();
        string _maNghe, _tenNghe, _dienGiai;
        DataTable dtbNgheNghiep = null;
        SqlCommand slqcom = null;
        SqlDataAdapter sqlDataAdapter = null;

        public clsNgheNghiep()
        {
            this._maNghe = "";
            this._tenNghe = "";
            this._dienGiai = "";
        }

        public clsNgheNghiep(string manghe, string tengnhe, string diengiai)
        {
            this._maNghe = manghe;
            this._tenNghe = tengnhe;
            this._dienGiai = diengiai;
        }

        public string MaNghe
        {
            get { return _maNghe; }
            set { this._maNghe = value; }
        }


        public string TenNghe
        {
            get { return _tenNghe; }
            set { this._tenNghe = value; }
        }

        public string DienGiai
        {
            get { return _dienGiai; }
            set { this._dienGiai = value; }
        }


        private bool DoesUserHavePermission()
        {
            try
            {
                SqlClientPermission clientPermission = new SqlClientPermission(PermissionState.Unrestricted);

                // will throw an error if user does not have permissions
                clientPermission.Demand();

                return true;
            }
            catch
            {
                return false;
            }
        }





        public DataTable GetAll_NgheNghiep()
        {
            da.ketnoiServer();
            dtbNgheNghiep = new DataTable();
            this.slqcom = new SqlCommand();
            this.slqcom.CommandText = "Select * from DMNghe";
            this.slqcom.Connection = da.con;
            this.slqcom.CommandType = CommandType.Text;
            this.sqlDataAdapter = new SqlDataAdapter(this.slqcom);
            this.sqlDataAdapter.Fill(dtbNgheNghiep);
            //da.da_closeConnect();
            return dtbNgheNghiep;
        }


        public DataTable Get_NgheNghiep()
        {
            da.ketnoiServer();
            dtbNgheNghiep = new DataTable();
            this.slqcom = new SqlCommand();
            this.slqcom.CommandText = "Select MaNghe, TenNghe from DMNghe";
            this.slqcom.Connection = da.con;
            this.slqcom.CommandType = CommandType.Text;
            this.sqlDataAdapter = new SqlDataAdapter(this.slqcom);
            this.sqlDataAdapter.Fill(dtbNgheNghiep);
            //da.da_closeConnect();
            return dtbNgheNghiep;
        }


        public void CapNhatNgheNghiep()
        {
            try
            {
                SqlCommandBuilder cb = new SqlCommandBuilder(sqlDataAdapter);
                sqlDataAdapter.Update(dtbNgheNghiep);
            }
            catch (SqlException e)
            {
                MessageBox.Show("Không thể thêm dữ liệu");
            }
        }

        public string getMacDinh()
        {
            da.ketnoiServer();
            this.slqcom = new SqlCommand();
            this.slqcom.CommandText = "Select TenNghe from DMNghe WHERE MacDinh = 1";
            this.slqcom.Connection = da.con;
            SqlDataReader reader = slqcom.ExecuteReader();
            reader.Read();
            string DefaultText = reader[0].ToString();
            da.da_closeConnect();
            return DefaultText;
        }
    }
}
